package br.com.vpsa.previdordevendas.model.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarUtils {

	public static final int ANOS_FUTUROS = 2;
	public static final int ANOS_PASSADOS = 3;
	public static final DateFormat DATA_SIMPLES = new SimpleDateFormat("dd/MM/yyyy");
	public static final DateFormat DATA_SERVICO = new SimpleDateFormat("dd-MM-yyyy");
	public static final DateFormat MES_ANO_FORMAT = new SimpleDateFormat("MM/yyyy");
	
	public static final Integer[] meses = new Integer[]{0,1,2,3,4,5,6,7,8,9,10,11};
	
	public static Calendar getCalendar( String data , DateFormat formato ){
		try {
			return getCalendar(formato.parse(data));
		} catch (ParseException e) {
			return null;
		}
	}
	
	public static Calendar getCalendar( Date date ){
		if( date == null ){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}
	
	public static int getAnoAtual(){
		return  Calendar.getInstance().get(Calendar.YEAR);
	}
	
	public static int getMesAtual(){
		return  Calendar.getInstance().get(Calendar.MONTH);
	}
	
	public static int getDiaAtual(){
		return  Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
	}

	public static String formatar(Date dataInvestimento) {
		return DATA_SIMPLES.format(dataInvestimento);
	}
	
	public static int mesesEntre(Calendar inicial , Calendar fim ){  
		int qtdMesesIni = (inicial.get(Calendar.YEAR) * 12) + inicial.get(Calendar.MONTH);
		int qtdMesesFim = (fim.get(Calendar.YEAR) * 12) + fim.get(Calendar.MONTH);
		return qtdMesesFim - qtdMesesIni;
	}
	
	public static void main(String[] args) {
		System.out.println( mesesEntre( getCalendar("01/01/2000",DATA_SIMPLES) , getCalendar("01/02/2000",DATA_SIMPLES)) );
	}
	
}
